package com.sun.draw.impl;

import com.sun.draw.api.AbstractDrawCommand;
import com.sun.draw.api.IDrawCommand;
import com.sun.draw.command.QueryInstantCommand;
import com.sun.draw.command.RandomWinCommand;
import com.sun.draw.command.ValidCommand;
import com.sun.draw.param.DrawParamContent;

/**
 * 执行具体的抽奖业务入口
* @ClassName: DrawCommandImpl  
* @author sunt  
* @date 2018年1月11日 
* @version V1.0
 */
public class DrawCommandImpl extends AbstractDrawCommand implements IDrawCommand{

	/**
	 * 日志
	 */
	//private Logger logger = LoggerFactory.getLogger(DrawCommandImpl.class);

	private static DrawCommandImpl drawCommandImpl = new DrawCommandImpl();
	
	/**
	 * 抽奖命令执行接口
	 */
	private IDrawCommand startCommand;
	
	/**
	 * 抽奖前置校验,分多个步骤执行，每次执行完成之后返回处理的结果集
	 * 满足条件继续执行下一个节点
	 * 前置规则校验-->奖品查询-->中奖概率的计算-->补发奖品操作-->记录中奖日志信息等操作
	 */
	public DrawCommandImpl() {
		//前置规则校验
		this.startCommand = new ValidCommand();
		//查询奖品信息
		IDrawCommand drawCommand = this.startCommand.setNextCommand(new QueryInstantCommand());
		//随机中奖概率计算
		drawCommand = drawCommand.setNextCommand(new RandomWinCommand());
	}

	public static synchronized DrawCommandImpl getInstance(){
		return drawCommandImpl;
	}
	
	public boolean execute(DrawParamContent drawParamContent) {
		//logger.info("------------->执行抽奖命令");
		return startCommand.run(drawParamContent);
	}

}
